<template>
	<view class="fill_container">
		<navBar title="进度填报" goBackUrl="/pages/homePage/homePage" @goBack="goBack"></navBar>
		   <view class="rel_box">
				<u-tabs :list="tabList" @click="fnTabClick" :current='type' :scrollable='false' :lineWidth="200" :inactiveStyle="{fontSize:'36rpx'}" :activeStyle="{color:'#2F80ED',fontWeight: '800',fontSize:'36rpx'}"></u-tabs>
				<!-- 角标 -->
				<view class="pos_box">{{badgeNum}}</view>
		   </view>
		<scroll-view scroll-y="true" class="scroll-box">
			<proFillForm v-show="type == 0" :editData="editData" ref="formRef" :isContinue="isContinue"></proFillForm>
			<workRecord v-show="type == 1" ref="recordRef" @sendBadge="sendBadge"></workRecord>
		</scroll-view>
		
	</view>
</template>

<script>
	import navBar from "@/components/navBar/navBar.vue"
	import proFillForm from './components/proFillForm.vue'
	import workRecord from './components/workRecord.vue'
	import mixins from '@/utils/mixins.js'
 	export default{
		name: "index",
		mixins:['mixins'],
		components: {
			navBar,
			proFillForm,
			workRecord
		},
		data() {
			return {
				tabList:[
					{
						type:0,
						name:'发起填报'
					},
					{
						type:1,
						name:'填报记录'
					}
				],
				type:0,
				isContinue:false,	//是否是继续填报按钮过来的
				editData:{},	//回显对象
				badgeNum:0,
			}
		},
		methods: {
			//子组件发送的获取角标事件
			sendBadge(val){
				this.badgeNum = val
			},
			//点击tab事件
			fnTabClick(val) {
				this.type = val.type
				this.isContinue = false
				this.$refs.formRef.form = {}
			},
			//navigateBack 发送的方法(在workLoad页面)
			getType(val) {
				this.type = val.type
				this.$refs.recordRef.getDataList()
				this.$refs.formRef.form = {}
			},
			// 返回上一级
			goBack(url){
				uni.switchTab({
					url: url
				})
			},
			// 转换日期 获得年月日
			getDate(date) {
			    var d = new Date(date);
			    let y = d.getFullYear();
			    let m = d.getMonth() + 1;
			    let did = d.getDate();
			    let h = d.getHours();
			    if(m<10){
			    m= '0' + m
			    };
			    if(did<10){
			    did  = '0' + did
			    };
			    if(h<10){
			    h  = '0' + h
			    };
			    let minute = d.getMinutes();
			    if(minute<10){
			    minute  = '0' + minute
			    };
			    let second = d.getSeconds();
			    if(second<10){
			    second  = '0' + second
			    };
			    return  y + '-' + m + '-' + did
			},
		},
		onLoad(options) {
			if(options && options.type) {
				this.type = options.type
			}
			if(options && options.isContinue) {
				this.isContinue = JSON.parse(options.isContinue)
				this.editData = JSON.parse(options.recordForm)
			}
		},
		mounted() {
			if(uni.getStorageSync('defaultForm')) {
				let storageData = JSON.parse(uni.getStorageSync('defaultForm'))
				//判断所选业主id是不是于存到本地的业主id相同（解决-切换业主，自动带出的数据是之前业主的项目数据的bug）
				console.log(this.$store)
				if(uni.getStorageSync('isOwner') === storageData.selectedOwnerId) {
					// console.log(storageData, '------');
					//从缓存中能读取到上次填报的记录并且不是继续填报过来的
					if(!this.isContinue) {
							this.$refs.formRef.form = {
							projectName:storageData.projectName,
							pmId:storageData.pmId,
							site:storageData.site,
							lineSiteSectionName:storageData.lineSiteSectionName,
							lineId:storageData.lineId,
							lineSiteSectionId:storageData.lineSiteSectionId,
							lineSiteSectionType:storageData.lineSiteSectionType,
							constructionDate:this.getDate(new Date),
							// type:storageData.constructionMethod === 'gh' ? '钢环' : '微扰动',
							type:this.$store.getters.dictMap['construction_method'].find(it => it.code === storageData.constructionMethod).name || null,
							constructionMethod:storageData.constructionMethod,
							managerPeo:storageData.managerPeo,
							handle:storageData.handle,
							pmprManagePersonList:storageData.pmprManagePersonList
						}
					}
				}
				
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fill_container {
		/* #ifdef MP-WEIXIN */
			padding-top: 180rpx;
		/* #endif */
	}
	.rel_box {
		position: relative;
		.pos_box {
			width: 40rpx;
			height: 40rpx;
			border-radius: 50%;
			background-color: red;
			color: #fff;
			position: absolute;
			top: 0rpx;
			right: 90rpx;
			text-align: center;
		}
	}
</style>